<template>
	<view class="content">
		<u-sticky>
			<!-- 只能有一个根元素 -->
			<view class="sticky">
				<u-search focus shape="square" @change="handleSearchValue" placeholder="请输入学校名称" v-model="keyword"
					@custom="handleSearchValue" @search="handleSearchValue"></u-search>
			</view>
		</u-sticky>
		<view v-if="list && list.length">
			<view @click="chooseItem(item)" class="item" v-for="(item,index) in list" :key="item.id">
			{{item.schoolCode}} - {{item.schoolName}}
			</view>
		</view>
		<view v-if="(!list || !list.length) && isOne">
			<uni-nodata></uni-nodata>
		</view>
	</view>
</template>

<script>
	import {
		common_query_school
	} from "@/api/school.js"
	export default {
		data() {
			return {
				isOne:false,
				keyword: "",
				list: []
			}
		},
		methods: {
			//点击选中
			chooseItem(item) {
				uni.setStorageSync('chooseSchoolObj', {
					'schoolName':item.schoolName,
					'schoolCode':item.schoolCode
				});
				uni.navigateBack(1);
			},
			//进行搜索
			handleSearchValue() {
				if(this.keyword && this.keyword.length >= 2){
					common_query_school({
						'schoolName': this.keyword
					}).then(res => {
						this.isOne = true;
						if (res.code === 100000) {
							this.list = res.data;
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 0 20rpx;
	}

	.item {
		border-bottom: 2rpx solid #e6e6ea;
		padding: 20rpx 10rpx;
	}
	
	.empty{
		width: 600rpx;
		margin: 0 auto;
		height: 600rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>